<template>
  <div>
    <div>
      <div class="addkpxx">
        <div>
          <a-button
            v-if="$parent.dfhymflag"
            type="primary"
            class="editable-add-btn"
            @click="shdzAdd"
          >新增收货地址</a-button>
          <span style="font-size: 18px; font-weight: bold;" v-if="!$parent.dfhymflag">收货地址</span>

        </div>
        <span>
          <a-icon v-if="$store.state.shdz" type="close" @click="close" />
        </span>
      </div>
      <div class="hydj" v-if="$store.state.tjhy">
        <shdztk class="hydj_xgym"></shdztk>
      </div>
      <a-table :dataSource="datashdz" :pagination="true" :columns="shdzcolumns">
        <template  slot="operation" slot-scope="text, record">
          <div v-if="$parent.dfhymflag" class="editable-row-operations">
            <span>
              <a class="del" @click="()=>xiugai(record)">修改</a>
              <a-popconfirm
                v-if="datashdz.length"
                title="确定删除吗?"
                @confirm="() => onDelete(record,record.key)"
              >
                <a >删除</a>
              </a-popconfirm>
            </span>
          </div>
        </template>
      </a-table>
    </div>
  </div>
</template>

<script>
import qs from "qs";
//收货地址---开始
const datashdz = [
  {
    key: "0",
    bh: "编号",
    name: "分类名称",
    paixu: "32",
    address: "London, Park Lane no. 0"
  },
  {
    key: "1",
    bh: "编号",
    name: "排序",
    paixu: "32",
    address: "London, Park Lane no. 1"
  }
];

const shdzcolumns = [
  {
    title: "收货人",
    dataIndex: "GSMC",
    scopedSlots: { customRender: "GSMC" }
  },
  {
    title: "联系电话",
    dataIndex: "lxdh",
    scopedSlots: { customRender: "lxdh" }
  },
  {
    title: "收货地址",
    dataIndex: "NR",
    scopedSlots: { customRender: "NR" }
  },
  {
    title: "默认",
    dataIndex: "MRBJ",
    scopedSlots: { customRender: "MRBJ" }
  },
  {
    title: "操作",
    dataIndex: "operation",
    scopedSlots: { customRender: "operation" }
  }
];
//收货地址---结束
import shdztk from "../shdz/shdztk.vue";

export default {
  data() {
    return {
      shdzcolumns,
      datashdz,
      kpxxphone: "",
      kpxxgsmc: ""
    };
  },

  methods: {
    // 收货地址
    shdzAdd() {
      this.$store.state.tjhy = true;
    },
    onDelete(value, key) {
      const datashdz = [...this.datashdz];
      this.datashdz = datashdz.filter(item => item.key !== key);
      this.axios
        .post(
          "huiyuan/addressDelete.php",
          qs.stringify({
            id_num: value.ID_NUM,
            hyphone: this.$parent.kpxxphone
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    xiugai(value) {
      this.$store.state.tjhy = true;
      this.$store.state.shdzbj = true;
      this.$store.state.editAddress = value;
      console.log(value);
    },
    getaddressList() {
      this.axios
        .post(
          "huiyuan/addressList.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid,
            hyphone: this.$parent.kpxxphone
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.datashdz = res.data.result.result;
            for (var i = 0; i < this.datashdz.length; i++) {
              this.datashdz[i].key = i;
            }
          } else {
            this.datashdz = [];
          }
        });
    },
    close() {
      this.$store.state.shdz = false;
      
    }
  },
  components: {
    shdztk
  },

  created() {
    this.kpxxphone = this.$parent.kpxxphone;
    // console.log(this.$parent.dfhymflag)

    this.getaddressList();
  }
};
</script>

<style lang='less'>
.addkpxx {
  display: flex;
  justify-content: space-between;
  padding: 20px 25px;
  text-align: left;
  i {
    font-size: 20px;
  }
}
</style>
